package cn.edu.seu.cose.qol.model.dao.config;

import java.io.IOException;

import cn.edu.seu.cose.qol.util.EnvironmentVariable;


public class QuestionnaireInfoAccess {
	
	private static final String BASIC_CONFIG_PROPERTIES_FILE_PATH = "config\\questionnaire_info.properties";
	
	private static final String ID_TITLE= "questionnaire.title";
	
	private static final String ID_VERSION = "questionnaire.version";
	
	private static final String ID_DESCRIPTION = "questionnaire.description";
	
	private static QuestionnaireInfoAccess _singleton;
	
	private PropertiesReader _reader;
	
	private PropertiesWriter _writer;
	
	public static synchronized QuestionnaireInfoAccess getInstance() throws IOException {
		if (_singleton == null) {
			EnvironmentVariable eV = EnvironmentVariable.getInstance();
			String webContentPath = eV.get(EnvironmentVariable.REAL_PATH);
			_singleton = new QuestionnaireInfoAccess(webContentPath);
		}
		
		return _singleton;
	}
	
	protected QuestionnaireInfoAccess(String webContentPath) throws IOException {
		String realPath = webContentPath + BASIC_CONFIG_PROPERTIES_FILE_PATH;
		_reader = PropertiesReader.getInstance(realPath);
		_writer = PropertiesWriter.getInstance(realPath);
	}
	
	public void setTitle(String title) throws IOException {
		_writer.setProperty(ID_TITLE, title);
	}
	
	public String getTitle() {
		return _reader.getProperty(ID_TITLE);
	}
	
	public void setVersion(String version) throws IOException {
		_writer.setProperty(ID_VERSION, version);
	}
	
	public String getVersion() {
		return _reader.getProperty(ID_VERSION);
	}
	
	public void setDescription(String description) throws IOException {
		_writer.setProperty(ID_DESCRIPTION, description);
	}
	
	public String getDescription() {
		return _reader.getProperty(ID_DESCRIPTION);
	}

}
